package com.example.controller;

import com.example.constant.MQConstant;
import com.example.po.SysMQMessage;
import com.example.template.SysMQTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.logging.Logger;

@RestController
public class SysTestController {

    Logger logger = Logger.getLogger(SysTestController.class.getName());

    @Resource
    private SysMQTemplate sysMQTemplate;

    /***
     * 发送队列消息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "sendQueue")
    public SysMQMessage sendQueue() {
        String uuid = UUID.randomUUID().toString();
        return sysMQTemplate.send(MQConstant.QUEUE, "xxxx.queue.listener", uuid);
    }

    /****
     * 批量发送mq消息
     * @return
     */
    @RequestMapping(value = "sendQueueBatch")
    public String sendQueueBatch() {
        for (int i = 0; i < 100; i++) {
            String uuid = UUID.randomUUID().toString();
            sysMQTemplate.send(MQConstant.QUEUE, "xxxx.queue.listener", uuid);
        }
       return "100";
    }

    /***
     * 发送主题消息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "sendTopic")
    public SysMQMessage sendTOPIC() {
        String uuid = UUID.randomUUID().toString();
        return sysMQTemplate.send(MQConstant.TOPIC, "xxxx.topic.listener", uuid);
    }
}
